<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./vue.global.js"></script>
  </head>

  <body>
    <div id="app">
      <anchored-heading :level="1" :href="'https://www.baidu.com'"
        >Hello world!</anchored-heading
      >
      <anchored-heading :level="2" :href="'https://www.baidu.com'"
        >Hello world!</anchored-heading
      >
      <anchored-heading :level="3" :href="'https://www.baidu.com'"
        >Hello world!</anchored-heading
      >
    </div>
    <script>
      const { createApp, h } = Vue;

      const app = createApp({});

      app.component("anchored-heading", {
        render() {
          return h(
            "h" + this.level, // 标签名
            {}, // prop 或 attribute
            [
              h(
                "a",
                { href: this.href },
                this.$slots.default() // 包含其子节点的数组
              ),
            ]
          );
        },
        props: {
          level: {
            type: Number,
            required: true,
          },
          href: {
            type: String,
            required: true,
          },
        },
      });

      app.mount("#app");
    </script>
  </body>
</html>
